package com.example.demo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.demo.adapter.MenuAdapter;
import com.example.demo.bean.MenuBean;
import com.example.demo.day1.SettingActivity;
import com.example.demo.day2.LoginActivity;
import com.example.demo.day3.NewsActivity;
import com.example.demo.day4.HomeActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TextView jump2RecyclerView;
    private TextView jump2Fragment;

    private RecyclerView menuListView;
    private MenuAdapter mMenuAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        menuListView = findViewById(R.id.rv_menu_content);
        menuListView.setLayoutManager(new LinearLayoutManager(this));

        mMenuAdapter = new MenuAdapter();
        menuListView.setAdapter(mMenuAdapter);

        List<MenuBean> menuBeans = new ArrayList<>();
        menuBeans.add(new MenuBean()
                .setTitle("第一天作业")
                .setJumpClass(SettingActivity.class));
        menuBeans.add(new MenuBean()
                .setTitle("第二天作业")
                .setJumpClass(LoginActivity.class)
        );
        menuBeans.add(new MenuBean()
                .setTitle("第三天作业")
                .setJumpClass(NewsActivity.class)
        );
        menuBeans.add(new MenuBean()
                .setTitle("第四天作业")
                .setJumpClass(HomeActivity.class)
        );

        mMenuAdapter.setList(menuBeans);


        mMenuAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                MenuBean bean = mMenuAdapter.getItem(position);
                if (bean != null && bean.getJumpClass() != null) {
                    startActivity(new Intent(MainActivity.this, bean.getJumpClass()));
                }
            }
        });


        jump2RecyclerView = findViewById(R.id.tv_jump_recycler);
        jump2RecyclerView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, RecyclerViewActivity.class));
            }
        });
        jump2Fragment = findViewById(R.id.tv_jump_fragment);
        jump2Fragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, FragmentActivity.class));
            }
        });
    }
}